<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>constant - Perl pragma to declare constants - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/constant">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="constant.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/constant">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/constant">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/constant">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/constant">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/constant">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/constant">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/constant">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/constant">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/constant">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/constant">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/constant">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/constant">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/constant">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/constant">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/constant">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/constant">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/constant">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/constant">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/constant">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/constant">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/constant">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/constant">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/constant">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/constant">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/constant">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/constant">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/constant">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/constant">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/constant">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/constant">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/constant">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/constant">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/constant">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/constant">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/constant">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/constant">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/constant">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/constant">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/constant">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/constant">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/constant">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/constant">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/constant">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/constant">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/constant">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/constant">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/constant">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/constant">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/constant">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/constant">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/constant">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/constant">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/constant">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/constant">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/constant">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/constant">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/constant">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/constant">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/constant">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/constant">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/constant">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/constant">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/constant">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/constant">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/constant">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/constant">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/constant">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/constant">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/constant">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/constant">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/constant">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/constant">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/constant">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/constant">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/constant">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/constant">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/constant">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/constant">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/constant">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/constant">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="constant.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/constant">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/constant">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/constant">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/constant">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/constant">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/constant">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/constant">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/constant">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/constant">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/constant">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/constant">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/constant">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/constant">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/constant">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/constant">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/constant">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/constant">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/constant">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/constant">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/constant">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/constant">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/constant">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/constant">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/constant">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/constant">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/constant">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/constant">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/constant">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/constant">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/constant">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/constant">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/constant">5.35.1</a>
          <a class="dropdown-item active" href="constant.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="constant.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="constant.html">constant</a>
          <div id="more">
            (<a href="constant.txt">source</a>,
            <a href="https://metacpan.org/pod/constant">CPAN</a>)
          </div>
            <div id="moduleversion">version 1.33</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="constant.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#NOTES">NOTES</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="constant.html#List-constants">List constants</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#Defining-multiple-constants-at-once">Defining multiple constants at once</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#Magic-constants">Magic constants</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#TECHNICAL-NOTES">TECHNICAL NOTES</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#CAVEATS">CAVEATS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#BUGS">BUGS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#AUTHORS">AUTHORS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="constant.html#COPYRIGHT-&amp;-LICENSE">COPYRIGHT &amp; LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="constant.html#NAME">#</a>NAME</h1>

<p>constant - Perl pragma to declare constants</p>

<h1 id="SYNOPSIS"><a class="permalink" href="constant.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use constant PI    =&gt; 4 * atan2(1, 1);
use constant DEBUG =&gt; 0;

print &quot;Pi equals &quot;, PI, &quot;...\n&quot; if DEBUG;

use constant {
    SEC   =&gt; 0,
    MIN   =&gt; 1,
    HOUR  =&gt; 2,
    MDAY  =&gt; 3,
    MON   =&gt; 4,
    YEAR  =&gt; 5,
    WDAY  =&gt; 6,
    YDAY  =&gt; 7,
    ISDST =&gt; 8,
};

use constant WEEKDAYS =&gt; qw(
    Sunday Monday Tuesday Wednesday Thursday Friday Saturday
);

print &quot;Today is &quot;, (WEEKDAYS)[ (localtime)[WDAY] ], &quot;.\n&quot;;</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="constant.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This pragma allows you to declare constants at compile-time.</p>

<p>When you declare a constant such as <code>PI</code> using the method shown above, each machine your script runs upon can have as many digits of accuracy as it can use. Also, your program will be easier to read, more likely to be maintained (and maintained correctly), and far less likely to send a space probe to the wrong planet because nobody noticed the one equation in which you wrote <code>3.14195</code>.</p>

<p>When a constant is used in an expression, Perl replaces it with its value at compile time, and may then optimize the expression further. In particular, any code in an <code>if (CONSTANT)</code> block will be optimized away if the constant is false.</p>

<h1 id="NOTES"><a class="permalink" href="constant.html#NOTES">#</a>NOTES</h1>

<p>As with all <code>use</code> directives, defining a constant happens at compile time. Thus, it&#39;s probably not correct to put a constant declaration inside of a conditional statement (like <code>if ($foo) { use constant ... }</code>).</p>

<p>Constants defined using this module cannot be interpolated into strings like variables. However, concatenation works just fine:</p>

<pre><code>print &quot;Pi equals PI...\n&quot;;        # WRONG: does not expand &quot;PI&quot;
print &quot;Pi equals &quot;.PI.&quot;...\n&quot;;    # right</code></pre>

<p>Even though a reference may be declared as a constant, the reference may point to data which may be changed, as this code shows.</p>

<pre><code>use constant ARRAY =&gt; [ 1,2,3,4 ];
print ARRAY-&gt;[1];
ARRAY-&gt;[1] = &quot; be changed&quot;;
print ARRAY-&gt;[1];</code></pre>

<p>Constants belong to the package they are defined in. To refer to a constant defined in another package, specify the full package name, as in <code>Some::Package::CONSTANT</code>. Constants may be exported by modules, and may also be called as either class or instance methods, that is, as <code>Some::Package-&gt;CONSTANT</code> or as <code>$obj-&gt;CONSTANT</code> where <code>$obj</code> is an instance of <code>Some::Package</code>. Subclasses may define their own constants to override those in their base class.</p>

<p>As of version 1.32 of this module, constants can be defined in packages other than the caller, by including the package name in the name of the constant:</p>

<pre><code>use constant &quot;OtherPackage::FWIBBLE&quot; =&gt; 7865;
constant-&gt;import(&quot;Other::FWOBBLE&quot;,$value); # dynamically at run time</code></pre>

<p>The use of all caps for constant names is merely a convention, although it is recommended in order to make constants stand out and to help avoid collisions with other barewords, keywords, and subroutine names. Constant names must begin with a letter or underscore. Names beginning with a double underscore are reserved. Some poor choices for names will generate warnings, if warnings are enabled at compile time.</p>

<h2 id="List-constants"><a class="permalink" href="constant.html#List-constants">#</a><a id="List"></a>List constants</h2>

<p>Constants may be lists of more (or less) than one value. A constant with no values evaluates to <code>undef</code> in scalar context. Note that constants with more than one value do <i>not</i> return their last value in scalar context as one might expect. They currently return the number of values, but <b>this may change in the future</b>. Do not use constants with multiple values in scalar context.</p>

<p><b>NOTE:</b> This implies that the expression defining the value of a constant is evaluated in list context. This may produce surprises:</p>

<pre><code>use constant TIMESTAMP =&gt; localtime;                # WRONG!
use constant TIMESTAMP =&gt; scalar localtime;         # right</code></pre>

<p>The first line above defines <code>TIMESTAMP</code> as a 9-element list, as returned by <code>localtime()</code> in list context. To set it to the string returned by <code>localtime()</code> in scalar context, an explicit <code>scalar</code> keyword is required.</p>

<p>List constants are lists, not arrays. To index or slice them, they must be placed in parentheses.</p>

<pre><code>my @workdays = WEEKDAYS[1 .. 5];            # WRONG!
my @workdays = (WEEKDAYS)[1 .. 5];          # right</code></pre>

<h2 id="Defining-multiple-constants-at-once"><a class="permalink" href="constant.html#Defining-multiple-constants-at-once">#</a><a id="Defining"></a>Defining multiple constants at once</h2>

<p>Instead of writing multiple <code>use constant</code> statements, you may define multiple constants in a single statement by giving, instead of the constant name, a reference to a hash where the keys are the names of the constants to be defined. Obviously, all constants defined using this method must have a single value.</p>

<pre><code>use constant {
    FOO =&gt; &quot;A single value&quot;,
    BAR =&gt; &quot;This&quot;, &quot;won&#39;t&quot;, &quot;work!&quot;,        # Error!
};</code></pre>

<p>This is a fundamental limitation of the way hashes are constructed in Perl. The error messages produced when this happens will often be quite cryptic -- in the worst case there may be none at all, and you&#39;ll only later find that something is broken.</p>

<p>When defining multiple constants, you cannot use the values of other constants defined in the same declaration. This is because the calling package doesn&#39;t know about any constant within that group until <i>after</i> the <code>use</code> statement is finished.</p>

<pre><code>use constant {
    BITMASK =&gt; 0xAFBAEBA8,
    NEGMASK =&gt; ~BITMASK,                    # Error!
};</code></pre>

<h2 id="Magic-constants"><a class="permalink" href="constant.html#Magic-constants">#</a><a id="Magic"></a>Magic constants</h2>

<p>Magical values and references can be made into constants at compile time, allowing for way cool stuff like this. (These error numbers aren&#39;t totally portable, alas.)</p>

<pre><code>use constant E2BIG =&gt; ($! = 7);
print   E2BIG, &quot;\n&quot;;        # something like &quot;Arg list too long&quot;
print 0+E2BIG, &quot;\n&quot;;        # &quot;7&quot;</code></pre>

<p>You can&#39;t produce a tied constant by giving a tied scalar as the value. References to tied variables, however, can be used as constants without any problems.</p>

<h1 id="TECHNICAL-NOTES"><a class="permalink" href="constant.html#TECHNICAL-NOTES">#</a><a id="TECHNICAL"></a>TECHNICAL NOTES</h1>

<p>In the current implementation, scalar constants are actually inlinable subroutines. As of version 5.004 of Perl, the appropriate scalar constant is inserted directly in place of some subroutine calls, thereby saving the overhead of a subroutine call. See <a href="perlsub.html#Constant-Functions">&quot;Constant Functions&quot; in perlsub</a> for details about how and when this happens.</p>

<p>In the rare case in which you need to discover at run time whether a particular constant has been declared via this module, you may use this function to examine the hash <code>%constant::declared</code>. If the given constant name does not include a package name, the current package is used.</p>

<pre><code>sub declared ($) {
    use constant 1.01;              # don&#39;t omit this!
    my $name = shift;
    $name =~ s/^::/main::/;
    my $pkg = caller;
    my $full_name = $name =~ /::/ ? $name : &quot;${pkg}::$name&quot;;
    $constant::declared{$full_name};
}</code></pre>

<h1 id="CAVEATS"><a class="permalink" href="constant.html#CAVEATS">#</a>CAVEATS</h1>

<p>List constants are not inlined unless you are using Perl v5.20 or higher. In v5.20 or higher, they are still not read-only, but that may change in future versions.</p>

<p>It is not possible to have a subroutine or a keyword with the same name as a constant in the same package. This is probably a Good Thing.</p>

<p>A constant with a name in the list <code>STDIN STDOUT STDERR ARGV ARGVOUT ENV INC SIG</code> is not allowed anywhere but in package <code>main::</code>, for technical reasons.</p>

<p>Unlike constants in some languages, these cannot be overridden on the command line or via environment variables.</p>

<p>You can get into trouble if you use constants in a context which automatically quotes barewords (as is true for any subroutine call). For example, you can&#39;t say <code>$hash{CONSTANT}</code> because <code>CONSTANT</code> will be interpreted as a string. Use <code>$hash{CONSTANT()}</code> or <code>$hash{+CONSTANT}</code> to prevent the bareword quoting mechanism from kicking in. Similarly, since the <code>=&gt;</code> operator quotes a bareword immediately to its left, you have to say <code>CONSTANT() =&gt; &#39;value&#39;</code> (or simply use a comma in place of the big arrow) instead of <code>CONSTANT =&gt; &#39;value&#39;</code>.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="constant.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="Readonly.html">Readonly</a> - Facility for creating read-only scalars, arrays, hashes.</p>

<p><a href="./Attribute::Constant.html">Attribute::Constant</a> - Make read-only variables via attribute</p>

<p><a href="./Scalar::Readonly.html">Scalar::Readonly</a> - Perl extension to the <code>SvREADONLY</code> scalar flag</p>

<p><a href="./Hash::Util.html">Hash::Util</a> - A selection of general-utility hash subroutines (mostly to lock/unlock keys and values)</p>

<h1 id="BUGS"><a class="permalink" href="constant.html#BUGS">#</a>BUGS</h1>

<p>Please report any bugs or feature requests via the perlbug(1) utility.</p>

<h1 id="AUTHORS"><a class="permalink" href="constant.html#AUTHORS">#</a>AUTHORS</h1>

<p>Tom Phoenix, &lt;<i>rootbeer@redcat.com</i>&gt;, with help from many other folks.</p>

<p>Multiple constant declarations at once added by Casey West, &lt;<i>casey@geeknest.com</i>&gt;.</p>

<p>Documentation mostly rewritten by Ilmari Karonen, &lt;<i>perl@itz.pp.sci.fi</i>&gt;.</p>

<p>This program is maintained by the Perl 5 Porters. The CPAN distribution is maintained by Sébastien Aperghis-Tramoni &lt;<i>sebastien@aperghis.net</i>&gt;.</p>

<h1 id="COPYRIGHT-&amp;-LICENSE"><a class="permalink" href="constant.html#COPYRIGHT-&amp;-LICENSE">#</a><a id="COPYRIGHT"></a><a id="COPYRIGHT-LICENSE"></a>COPYRIGHT &amp; LICENSE</h1>

<p>Copyright (C) 1997, 1999 Tom Phoenix</p>

<p>This module is free software; you can redistribute it or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
